package com.neuedu.string;

public class StringExample {

	public static void main(String[] args) {
		//String StringBuilder StringBuffer
		/**
		 * String:不可变的字符串
		 * 
		 * StringBuider StringBuffer:可变长度的字符串
		 * StringBuilder：线程不安全，主要实现单线程：java1.5
		 * StringBuffer：线程安全，可是实现多线程；性能上相对低；java1.0
		 */
		
		/**
		 * 案例：1："112 2223 2222"--->"12322232222"
		 *     2:"12322232222"-->"112 2223 2222"
		 */
		
		String sourceStr="112 2223 2222";
		String[] strs=sourceStr.split("\\s");//拆分
		
		StringBuilder sbder=new StringBuilder();
		
		for(String str:strs) {
			sbder.append(str);
		}
		System.out.println(sbder);
		
		String targetStr=new String(sbder);
        String str1=targetStr.substring(0, 3);//取子串
        String str2=targetStr.substring(3,7);
        String str3=targetStr.substring(7,targetStr.length());
        
        StringBuilder tarder=new StringBuilder();
        tarder.append(str1+" "+str2+" "+str3);//拼接
        
        String webStr=new String(tarder);
        System.out.println(webStr);
        
        
	}

}
